#include "mesh_testFunctions.hpp"
#include "mesh.hpp"
#include "util.hpp"

using namespace hms;


hms::Mesh testMeshMixed( bool createCells ) {
	/* mesh looks like this:
	 *      0
	 *     /\
	 *   1/__\2
	 *    |  |
	 *    |__|
	 *   3    4
	 * 
	 * edges:
	 *      
	 *    0/\1
	 *    /__\
	 *    | 2|
	 *   3|__|4
	 *      5
	 */
	/* each column represents the 2D cartesian coordinates of one vertex */
	Matrix2Xs vertices ( hms::dims, 5 );
	vertices <<
		1, 0, 2, 0, 2,
		4, 2, 2, 0, 0;
	
	/* each column represents the endpoints of an edge */
	Array2Xi vertexIndices ( 2, 6 );
	vertexIndices <<
		0, 0, 1, 1, 2, 3, 
		1, 2, 2, 3, 4, 4;
	
	if (createCells)
		return { std::move(vertices), std::move(vertexIndices) };
	else
		return { std::move(vertices), std::move(vertexIndices), bool{} };
}


hms::Mesh testMeshRectangles( bool createCells )
{
	/*    vertices           edges            cells          origin
	 *  2_____5_____8     _10____11__      ___________     ___________
	 *  |     |     |    |     |     |    |     |     |   |     y     |
	 *  |     |     |   1|    3|    5|    |  1  |  3  |   |    / \    |
	 *  1_____4_____7    |_____|_____|    |_____|_____|   |_____|__\ x
	 *  |     |     |    |  8  |  9  |    |     |     |   |    0|  /  |
	 *  |     |     |   0|    2|    4|    |  0  |  2  |   |     |     |
	 *  0_____3_____6    |_____|_____|    |_____|_____|   |_____|_____|
	 *                      6     7
	 */
	Matrix2Xs vertices (2, 9);
	vertices <<
	    -1, -1, -1,  0,  0,  0,  1,  1,  1,
	    -1,  0,  1, -1,  0,  1, -1,  0,  1;
	/*	#0  #1  #2  #3  #4  #5  #6  #7  #8 */
	
	
	Array2Xi vertexIndices (2, 12);
	vertexIndices <<
	    0, 1, 3, 4, 6, 7,   0, 3, 1, 4, 2, 5,
		1, 2, 4, 5, 7, 8,   3, 6, 4, 7, 5, 8;
	
	if (createCells)
		return { std::move(vertices), std::move(vertexIndices) };
	else
		return { std::move(vertices), std::move(vertexIndices), bool{} };
}


hms::Mesh testMeshTriangles( bool createCells )
{
	/*    vertices              edges                cells
	 *
	 *      3_____4             __7___              ______       
	 *    ,/\    /\          6,/\    /\           ,/\    /\       
	 *  2/   \  /  \         /   2  1  8         / 2 \ 1/ 0\      
	 *   \`'-,\/____\        \`'3,\/____\        \`'-,\/____\     
	 *    \  ./0     5        5  ./   0           \ 3./    
	 *     \/                  \/4                 \/           
	 *     1
	 */
	
	Matrix2Xs vertices (2, 6);
	vertices <<
	     0, -2, -3, -1,  1,  2,
	     0, -2,  1,  3,  3,  0;
	/*  #0  #1  #2  #3  #4  #5  */
	
	Array2Xi vertexIndices (2, 9);
	vertexIndices <<
	    5, 4, 3, 2, 1, 1, 2, 3, 4,
	    0, 0, 0, 0, 0, 2, 3, 4, 5;
	
	if (createCells)
		return { std::move(vertices), std::move(vertexIndices) };
	else
		return { std::move(vertices), std::move(vertexIndices), bool{} };
}